﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class News : Basic
{
    public string strList="";
    public string strClass = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        string tid = OTO.ToStr(Request["tid"], "0401");
        strClass = Pub.LoadData(jsonUrl + "news/TypeNameByTypeId.ashx?typeid=" + tid);
        
        strList = sb文章列表().ToString();
    }

    protected StringBuilder sb文章列表()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string tid = OTO.ToStr(Request["tid"], "0401");
            string url = jsonUrl + "news/NewsList.ashx?typeid=" + tid;
            NewsList obj = JsonConvert.DeserializeObject<NewsList>(Pub.LoadData(url));
            if (obj.list.Length > 0)
            {

                int _totalCount = 0;
                int _pagesize = 2;
                int _totalPage = 0;
                _totalCount = obj.list.Length;
                if (_totalCount > 0)
                {
                    if ((_totalCount % _pagesize) == 0)
                        _totalPage = _totalCount / _pagesize;
                    else
                        _totalPage = (int)(_totalCount / _pagesize) + 1;
                }
                int page = OTO.ToInt(Request["page"], 1);
                if (page == 0)
                    page = 1;
                if (page > _totalPage)
                    page = _totalPage;
                int _index = (page - 1) * _pagesize;
                int _end = page * _pagesize;
                if (page == _totalPage && (_totalCount % _pagesize) != 0)
                    _end = (page - 1) * _pagesize + _totalCount % _pagesize;

                string strPage = "<div class=\"news_next\">" + PageHelper.ShowPage( page, _totalCount, _pagesize,Request.Url.AbsoluteUri) + "</div>";

                for (int i = _index; i < _end; i++)
                {
                    sb.AppendFormat("<div class=\"title mt20\"><a href=\"NewsContent_{1}_{2}.shtml\"><span>{0}</span> </a></div>", obj.list[i].Title, obj.list[i].Id, obj.typeid);

                    NewsContentEnty obj2 = JsonConvert.DeserializeObject<NewsContentEnty>(Pub.LoadData(jsonUrl + "/news/UNews.ashx?id=" + obj.list[i].Id));
                    if (obj2 != null)
                    {
                        sb.AppendFormat("<div class=\"right_content mt20\">{0}</div>", obj2.Content);
                    }
                    else
                    {
                        sb.AppendFormat("<div class=\"right_content mt20\">&nbsp;&nbsp;</div>");
                    }

                }
                sb.AppendLine("<div class=\"clearok\"></div>");
                sb.AppendLine(strPage);
            }


        }
        catch
        { }
        return sb;
    }

}